package top.ffhome.util.core;

public class UEditorUtil {
	/**
	 * 将富文本内容可以使用hightlight高亮显示处理
	 * 在代码pre中增加code标签处理
	 * @param str
	 * @return
	 */
	public static String highlight(String str) {
		String[] arr = StrUtil.split(str, "<pre class=\"brush:");
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < arr.length; i++) {
			if (i == 0) {
				sb.append(arr[i]);
				continue;
			}
			String code = StrUtil.subBefore(arr[i], ";", false);
			if ("js".equals(code)) {
				code = "javascript";
			}
			sb.append("<pre class=\"brush:");
			sb.append(StrUtil.subBefore(arr[i], ">", false));
			sb.append("><code class=\"hljs " + code + "\">");
			String s = StrUtil.subAfter(arr[i], ">", false);

			sb.append(StrUtil.subBefore(s, "</pre>", false));
			sb.append("</code></pre>");
			sb.append(StrUtil.subAfter(s, "</pre>", false));
		}
		return sb.toString();
	}
}
